package no.ntnu.fp.mmi;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;

import no.ntnu.fp.su.LogEntry;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
@SuppressWarnings("serial")
public class AddCommentPanel extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JLabel jLabel1;
	private JButton closeButton;
//	private JScrollBar jScrollBar1;
	private JTextArea jTextArea1;
	private JScrollPane jScrollPane1;
	private JButton addCommentButton;
	private LogEntry id;
	Font font = new Font("Candera", Font.BOLD, 17);
	private LogPanel panel;
	/**
	* Auto-generated main method to display this JFrame
	*/

	/**
	 * Create new AddCommentPanel from watch-window
	 * 
	 * @param {@link logg} loggentry comment is added to
	 *        
	 * @param {@link panel}  came from this panel
	 *
	 */
	public AddCommentPanel(LogEntry logg, LogPanel panel) {
		super();
		this.panel = panel;
		this.id = logg;
			try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setFont(font);
				jLabel1.setText("Add Comment");
				jLabel1.setBounds(107, 12, 145, 28);
			}
			{
				closeButton = new JButton();
				getContentPane().add(closeButton);
				closeButton.setText("Close");
				closeButton.setBounds(202, 218, 83, 23);
				closeButton.addActionListener(new closeButtonEvent());
				
			}
			{
				addCommentButton = new JButton();
				getContentPane().add(addCommentButton);
				addCommentButton.setText("Add");
				addCommentButton.setBounds(86, 218, 90, 23);
				addCommentButton.addActionListener(new addCommentEvent());
			}
			{
				jTextArea1 = new JTextArea();
				getContentPane().add(getJTextArea1());
				jTextArea1.setForeground(Color.white);
				jTextArea1.setBackground(Color.lightGray);
				jTextArea1.setBounds(40, 52, 315, 139);
				{
					jScrollPane1 = new JScrollPane();
					jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
					jTextArea1.add(jScrollPane1);
			
				}

			}
			
		
			
			

		
			setSize(400, 300);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public JTextArea getJTextArea1() {
		return jTextArea1;
	}
	/**
	 * ActionListener for close button, closes panel
	 * 
	 */
	public class closeButtonEvent implements ActionListener{
		 
				public void actionPerformed(ActionEvent e) {
					Object[] option = {"Yes", "No"};
					int val = javax.swing.JOptionPane.showOptionDialog(null, "Are you sure you want to close without saving?",
			                "Cancel?", javax.swing.JOptionPane.YES_NO_OPTION,
			                javax.swing.JOptionPane.QUESTION_MESSAGE, null, option, option[0]);
			        
			        if(val == 0) {
			        	panel.enable();
			            dispose();						
				}
				}
			}
	
	/**
	 * Listener for add button, this adds a comment
	 */
	public class addCommentEvent implements ActionListener {
				public void actionPerformed(ActionEvent arg0) {
					id.newComment(jTextArea1.getText());
					JOptionPane.showMessageDialog(null	, "Your Comment is Added", "Comment Added", JOptionPane.INFORMATION_MESSAGE);
					panel.reDraw();
					dispose();
				}
			}	
	
	
	
}

